﻿// See https://aka.ms/new-console-template for more information
Console.WriteLine("--- 石头 剪刀 布 --- 小游戏");
Console.WriteLine("---1.石头 2.剪刀 3.布-----");
int c = 0;
int pcWin = 0;
int stuWin = 0;
do
{
    //电脑生成完毕：
    Console.WriteLine("电脑生成完毕：*** \r\n 请小朋友出：");
    Random random = new Random();
    int r = random.Next(1, 3);// 转换成石头剪刀布
    string Info = StoneCutBuInfo(r);
    string StoneCutBuInfo(int i)
    {
        switch (i)
        {
            case 1:
                return "石头";
            case 2:
                return "剪刀";
            case 3:
                return "布";
            default:
                return "电脑出错";
        }
    }

    ConsoleKeyInfo consoleKeyInfo  = Console.ReadKey(true);
    if (consoleKeyInfo.Key == ConsoleKey.D1 || consoleKeyInfo.Key == ConsoleKey.D2 || consoleKeyInfo.Key == ConsoleKey.D3)
    {
        Console.WriteLine($"\n\r\n\r\n\r电脑生成完毕：「{Info}」 \r\n 小朋友出的：『{StoneCutBuInfo((int)consoleKeyInfo.Key-48)} 』\r\n============锁定{++c}次结果：『{DateTime.Now}』===========");
        //公布结果
        int r1 = (int)consoleKeyInfo.Key - 48;
        string winner = JudgeByNumber(r, r1);
        if (winner.Contains("小朋友"))
        {
            stuWin++;
        }
        if (winner.Contains("电脑"))
        {
            pcWin++;
        }
        
        Console.WriteLine($"{winner}\r\n*************************");
        //统计结果：三局两胜
        Console.WriteLine($"##############################################################################");
        Console.WriteLine($"#统计结果，有效次数：「{c}」,电脑：「{pcWin}」, 小朋友：「{stuWin}」#");
        Console.WriteLine($"##############################################################################");
        if ((stuWin+pcWin)%3==0)
        {
            if (pcWin > stuWin)
            {
                Console.WriteLine("三局两胜：电脑赢了！");
            }
            else
            {
                Console.WriteLine("三局两胜：小朋友赢了！");
            }

            pcWin = 0;
            stuWin = 0;
        }
    }
    else
    {
        Console.WriteLine("小朋友：---1.石头 2.剪刀 3.布-----\r\n");
    }
} while (true);
//判定逻辑实现
static string JudgeByNumber(int player1Choice, int player2Choice)
{
    if (player1Choice == player2Choice)
    {
        return "平局";
    }
    else if ((player1Choice == 1 && player2Choice == 3)  // 剪刀（1）胜布（3）
             || (player1Choice == 2 && player2Choice == 1)  // 石头（2）胜剪刀（1）
             || (player1Choice == 3 && player2Choice == 2)) // 布（3）胜石头（2）
    {
        return "小朋友赢了！";
    }
    else
    {
        return "电脑赢了！";
    }
}

